﻿using System;
using System.Text.RegularExpressions;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class public_html_NewSiteTest_Releaseliste : System.Web.UI.Page
{
    public string SpilID = "";
    public string Format = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        DateFromMySql NewDate = new DateFromMySql();
        ReviewerMySql SQL = new ReviewerMySql();
        int i = 0;
        int x = 0;

        string SQLsaetning = "";

        string Format = Request.QueryString["Format"];
        string Bogsta = Request.QueryString["Bogstav"];
        string Search = Request.QueryString["Ord"];
        string FoNavn = Request.QueryString["Navn"];

        string[] BogStaver = Regex.Split("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", ",");

        HyperLinkXbox.NavigateUrl = "?Navn=Xbox 360&Format=1&Bogstav=" + Bogsta;
        HyperLinkPC.NavigateUrl = "?Navn=PC&Format=2&Bogstav=" + Bogsta;
        HyperLinkPlayStation3.NavigateUrl = "?Navn=Playstation 3&Format=3&Bogstav=" + Bogsta;
        HyperLinkNintendoWii.NavigateUrl = "?Navn=Nintendo Wii&Format=4&Bogstav=" + Bogsta;

        DivBogstaver.InnerHtml = "";
        foreach (string bogstav in BogStaver)
        {
            DivBogstaver.InnerHtml += "<a href=\"Screenshots.aspx?Navn=" + FoNavn + "&Format=" + Format + "&Bogstav=" + bogstav + "\">" + bogstav + "</a>  ";
        }

        if (Format == "" || Bogsta == "" || Format == null || Bogsta == null)
        {
            SQLsaetning = "SELECT V2_Screenshots.*, V2_Spil.Titel, V2_GloFormat.Navn FROM V2_Screenshots JOIN V2_Spil ON V2_Spil.SpilID = V2_Screenshots.SpilID JOIN V2_GloFormat ON V2_Screenshots.Format = V2_GloFormat.id ORDER BY V2_Screenshots.id DESC";
            lblOverskrift.Text = "Seneste screenshots";
        }

        if (Format == "" && Bogsta != "")
        {
            SQLsaetning = "SELECT V2_Screenshots.*, V2_Spil.Titel, V2_GloFormat.Navn FROM V2_Screenshots JOIN V2_Spil ON V2_Spil.SpilID = V2_Screenshots.SpilID JOIN V2_GloFormat ON V2_Screenshots.Format = V2_GloFormat.id WHERE V2_Spil.Titel LIKE '" + Bogsta + "%' ORDER BY V2_Screenshots.id DESC";
            lblOverskrift.Text = "Seneste screenshots: " + Bogsta;
        }

        if (Format != "" && Format != null && Bogsta != null && Bogsta != "")
        {
            SQLsaetning = "SELECT V2_Screenshots.*, V2_Spil.Titel, V2_GloFormat.Navn FROM V2_Screenshots JOIN V2_Spil ON V2_Spil.SpilID = V2_Screenshots.SpilID JOIN V2_GloFormat ON V2_Screenshots.Format = V2_GloFormat.id WHERE V2_Spil.Titel LIKE '" + Bogsta + "%' AND V2_Screenshots.Format = '" + Format + "' ORDER BY V2_Screenshots.id DESC";
            lblOverskrift.Text = "Seneste screenshots: " + Bogsta + " til " + FoNavn;
        }

        if (Format != "" && Bogsta == "")
        {
            SQLsaetning = "SELECT V2_Screenshots.*, V2_Spil.Titel, V2_GloFormat.Navn FROM V2_Screenshots JOIN V2_Spil ON V2_Spil.SpilID = V2_Screenshots.SpilID JOIN V2_GloFormat ON V2_Screenshots.Format = V2_GloFormat.id WHERE V2_Screenshots.Format = '" + Format + "' ORDER BY V2_Screenshots.id DESC";
            lblOverskrift.Text = "Seneste screenshots til " + FoNavn;
        }

        int ScreenCounter = 0;
        string TempTitel = "";
        DivResult.InnerHtml = "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-top:1px solid #666666;\">";
        OdbcDataReader MainReader = SQL.ExecuteReader(SQLsaetning);
        ScreenCounter = 0;
        while (MainReader.Read() && ScreenCounter != 20)
        {
            if (TempTitel != MainReader["Titel"].ToString())
            {
                OdbcDataReader SubReader = SQL.ExecuteReader("SELECT COUNT(*) AS Ialt FROM V2_Screenshots WHERE SpilID = '" + MainReader["SpilID"].ToString() + "'");
                SubReader.Read();
                DivResult.InnerHtml += "<tr><td width=\"120px\" class=\"TD_Screenlist\"><a style=\"color:black;\" href=\"Screenshot.aspx?PicID=" + MainReader["id"].ToString() + "&SpilID=" + MainReader["SpilID"].ToString() + "\">&nbsp;<a href=\"Screenshot.aspx?PicID=" + MainReader["id"].ToString() + "&SpilID=" + MainReader["SpilID"].ToString() + "\"><img style=\"border:1px solid black;\" height=\"60px\" width=\"100px\" src=\"screenshots/" + MainReader["Filnavn"].ToString() + "\"></td><td class=\"TD_Screenlist\">" + MainReader["Titel"].ToString() + "<br/>" + MainReader["Navn"].ToString() + "<br />Screenshots: " + SubReader["Ialt"].ToString() + "</a></td></tr>";
                ScreenCounter++;
            }
            TempTitel = MainReader["Titel"].ToString();
            
        }
        DivResult.InnerHtml += "</table>";
        //HtmlMeta HeaderDescription = new HtmlMeta();
        //HeaderDescription.Name = "description";
        //HeaderDescription.Content = "Screenshots af spil til PlayStation 3, Xbox 360, Wii og PC";
        //this.Header.Controls.Add(HeaderDescription);
    }
}
